module.exports = app => {
  const { STRING, INTEGER ,DATE,TINYINT} = app.Sequelize;

  const InvoiceTitle = app.model.define('invoice_title', {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    user_id: {
      type: INTEGER,
      allowNull: true,
      comment: '用户ID',
    },
    is_default:{
      type: TINYINT,
    },
    tax_identification_number: {
      type: STRING(40),
      allowNull: true,
      comment: '税号',
    },
    address: {
      type: STRING,
      allowNull: true,
      comment: '单位地址',
    },
    phone: {
      type: STRING,
      allowNull: true,
      comment: '电话号码',
    },
    deposit_bank: {
      type: STRING,
      allowNull: true,
      comment: '开户银行',
    },
    title: {
      type: STRING,
      allowNull: true,
      comment: '发票抬头',
    },
    bank_account: {
      type: STRING,
      allowNull: true,
      comment: '银行账户',
    },
    created_at: DATE,
    updated_at: DATE,
  }, {
    tableName: 'invoice_titles',
    timestamps: true,
    underscored: true,
  });

  InvoiceTitle.associate = function() {
    // 定义与用户的关联关系
    app.model.InvoiceTitle.belongsTo(app.model.User, { foreignKey: 'user_id' });
  };

  return InvoiceTitle;
};
